package com.hsd.znsh.controller.app;

import com.hsd.znsh.code.ValidateCodeProcessor;
import com.hsd.znsh.code.ValidateCodeProcessorHolder;
import com.hsd.znsh.entity.Host;
import com.hsd.znsh.entity.Monitor;
import com.hsd.znsh.entity.User;
import com.hsd.znsh.exception.ZnshException;
import com.hsd.znsh.pojo.input.APPRegisterUser;
import com.hsd.znsh.pojo.output.MonitorVO;
import com.hsd.znsh.pojo.output.ResultVO;
import com.hsd.znsh.pojo.query.MonitorQuery;
import com.hsd.znsh.service.*;
import com.hsd.znsh.utils.ResultVOUtil;
import com.hsd.znsh.utils.ValidatorUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.util.StringUtils;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.context.request.ServletWebRequest;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import java.util.List;

/*
 * @auther: wangjiacai
 *
 * @create: 2018-04-23 11:24:39
 */
@RequestMapping("/app/monitor")
@RestController
public class AppMonitorController {

    @Autowired
    private MonitorService monitorService;

    @Autowired
    private RedisService redisService;

    @GetMapping("/getMonitorListByHostSn")
    public ResultVO getMonitorListByHostSn(String hostSn){
        if(StringUtils.isEmpty(hostSn)) throw new ZnshException("主机编号不能为空");
        List<Monitor> list=monitorService.getMonitorListByHostSn(hostSn);
        return ResultVOUtil.success(list);
    }

    @GetMapping("/getMonitorList")
    public ResultVO getMonitorList(@RequestHeader("token") String token){
        User user=redisService.get(token,User.class);
        List<MonitorVO> list=monitorService.getMonitorListByAppUser(user);
        return ResultVOUtil.success(list);
    }

    @GetMapping("/countMonitorByHostSn")
    public ResultVO countMonitorByHostSn(String hostSn){
        return ResultVOUtil.success(monitorService.countMonitorByHostSn(hostSn));
    }
}
